#include <iostream>

using namespace std;
int main()
{
	int empty = 0;
	while (cin >> empty)
	{
		if (empty == 0)
			break;
		int sum = 0;
		while (empty > 1)
		{
			int res = empty / 3; //所能兑换的个数
			int left = empty % 3; //遗下的个数
			sum += res;
			empty = left + res;
			if (empty == 2)
			{
				sum++;
				break;
			}
		}
		cout << sum << endl;
	}
	return 0;
}